package xyz.paragon.auth;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;

import xyz.paragon.auth.keycloak.KeycloakServerProperties;

@SpringBootApplication(exclude = LiquibaseAutoConfiguration.class)
@EnableDiscoveryClient
@EnableConfigurationProperties({ KeycloakServerProperties.class })
public class AuthApplication {

	private static final Logger log = LoggerFactory.getLogger(AuthApplication.class);

	public static void main(String[] args) {
		SpringApplication.run(AuthApplication.class, args);
	}

	@Bean
	ApplicationListener<ApplicationReadyEvent> onApplicationReadyEventListener(
		ServerProperties serverProperties,
		KeycloakServerProperties keycloakServerProperties) {

			return (evt) -> {

				Integer port = serverProperties.getPort();
				String keycloakContextPath = keycloakServerProperties.getContextPath();
	
				log.info("Embedded Keycloak started: http://localhost:{}{} to use keycloak", port, keycloakContextPath);
			};
	}
}
